package com.tyut.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.sql.SQLException;

public class BaseUtils {

     //初始化c3p0
     private static DataSource dataSource=null;

     static{
         dataSource = new ComboPooledDataSource();
     }

     public static QueryRunner getQueryRunner(){
         QueryRunner query=new QueryRunner(dataSource);
         return query;
     }

     public static boolean addUpdateDelete(String sql,Object[] arr){
         QueryRunner qr=getQueryRunner();
         int count;
         try {
             count = qr.update(sql, arr);
             if(count>0){
                 return true;
             }else{
                 return false;
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return false;
     }

 }
